<?php
namespace app\middleware;
//引用的JWT

class Auth
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next){
        try {            
            $header = $request->header(); // token 合法          
            $timestamp = isset($header['timestamp'])?$header['timestamp']:0;
            $signature = isset($header['signature'])?$header['signature']:'';
            if($timestamp<(time()-5*60)){
                return json(['code'=>201,'success'=>false,'message'=>'签名失效']);
            }
            if($signature!=strtoupper(md5($timestamp.'.darong1994.cn'))){
                return json(['code'=>201,'success'=>false,'message'=>'签名失效']);
            }
      
        }catch (Exception $e){            
            return json(['code'=>201,'success'=>false,'message'=>'签名失效','msg'=>$e]);       
        }
        return $next($request); 
    }
}
